﻿@model SIG.ViewModel.Admin.LogSearchVM


@{
    ViewBag.PageTitle = "系统日志";
    ViewBag.Title = ViewBag.PageTitle + "_安全"; 

}

<div class="panel panel-default">
        <header class="panel-heading">
            <span class="glyphicon glyphicon-file"></span> @ViewBag.PageTitle
        </header>

        <section class="panel-body">
            <button class="btn btn-danger delete-link pull-right" type="button" data-url="@Url.Action("Delete", new {Id = "all"})"><span class="glyphicon glyphicon-trash"></span> 清空日志</button>

            @using (Html.BeginForm("Index", "Logs", FormMethod.Get, new { @class = "form-inline" }))
            {
                <div class="form-group">
                    <label>开始时间</label>
                    @Html.TextBox("startDate", null, new { type = "date", @class = "form-control" })
                </div>
                <div class="form-group">
                    <label>结束时间</label>
                    @Html.TextBox("expireDate", null, new { type = "date", @class = "form-control" })
                </div>
                <div class="form-group">
                    <label>等级</label>
                    @Html.DropDownList("level", (IEnumerable<SelectListItem>)Model.LevelItems, new { @class = "form-control" })

                </div>
                <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 搜索</button>
            }


        </section>

        <div class="table-responsive">

        <table class="table table-striped">
            <thead>
                <tr>
                    <th>
                        时间
                    </th>
                    <th>
                        线程
                    </th>
                    <th>
                        等级
                    </th>
                   
                    <th>
                        消息
                    </th>
                    <th>
                        错误
                    </th>
                    <th>
                        用户名
                    </th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Logs)
            {
                    <tr class="item-container" id="@string.Format("container{0}",item.Id)">
                        <td>
                            @Html.DisplayFor(modelItem => item.Date)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Thread)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Level)
                        </td>
                       
                        <td>
                            @Html.DisplayFor(modelItem => item.Message)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Exception)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.UserName)
                        </td>
                        <td>
                            @*@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
                                @Html.ActionLink("Details", "Details", new { id=item.Id},new{@class="btn btn-primary"}) |*@
                            @*@Html.ActionLink("Delete", "Delete", new { id=item.Id }, new{@class="btn btn-danger"})*@

                            <button data-url="@Url.Action("Delete", new {Id = item.Id})" class="btn btn-xs btn-danger delete-item" type="button"><span class="glyphicon glyphicon-trash"></span></button>
                        </td>
                    </tr>

                }
            </tbody>
        </table>
    </div>
        <div class="panel-footer text-center">
            @Html.PagedListPager((IPagedList)ViewBag.OnePageOfLogs, page => Url.Action("Index",
           new { page, startDate = Model.StartDate, expireDate = Model.ExpireDate, level = Model.Level }))
        </div>

    </div>




@section footer {

    <script>

        $(function () {

            //delete
            $(document).on("click", '.delete-item', function (e) {
                e.preventDefault();

                var url = $(this).attr('data-url');
                var that = $(this);
                bootbox.setLocale("zh_CN");
                bootbox.confirm("你确定要删除此项吗？", function (result) {
                    if (result) {
                        /*DELETE*/
                        var title = "@ViewBag.Title";
                        Common.DeleteItem(url, title, that);
                    }
                });

            });

            //删除数据
            $('.delete-link').click(function (e) {
                var url = $(this).attr('data-url');
                var that = $(this);
                console.log(url);
                /*DELETE*/
                $.ajax({
                    url: url,
                    dataType: "json",
                    type: "POST",
                    contentType: 'application/json; charset=utf-8',
                    data: JSON.stringify({}),
                    async: true,
                    processData: false,
                    cache: false,
                    success: function (data) {

                        switch (data.Status) {
                            case 2:
                                toastr.error(data.Message, '删除日志');
                                break;
                            case 3:
                                toastr.info(data.Message, '删除日志');
                                break;
                            case 4:
                                toastr.warning(data.Message, '删除日志');
                                break;
                            case 1:
                                toastr.success(data.Message, '删除日志');
                                setTimeout(function () {
                                    location.reload();
                                },2000)
                        }


                    },
                    error: function (xhr) {
                        toastr.error('日志删除失败！', '删除日志');
                    }
                });


                e.preventDefault();
            });

        });
    </script>
}
